<template>
	<view>
		<view>
			<view v-for="(msg, index) in msgs" :key="index" class="padding-sm">
				<view @tap="toChat(msg.fromid)" class="bg-white shadow radius padding-sm flex justify-start align-center relative">
					<image style="width: 30px; height: 30px;" class="round"
						mode="aspectFill"
						:src="msg.fromcover"></image>
					<text class="padding-sm">{{msg.fromnc}}</text>
					<text class="padding-xxs padding-left-xs padding-right-xs text-xs bg-red round">{{msg.wdxx}}个消息未读</text>
				</view>
			</view>
		</view>
		<view v-if="msgs.length < pageInfo.total" class="padding ">
			<button @tap="loadMore" class="cu-btn block bg-main lg">显示更多</button>
		</view>
	</view>
	
</template>

<script>
	export default {
		data: function() {
			return {
				msgs: [],
				pageInfo: {
					current: 1,
					size: 16,
					total: 0,
					toid: this.store.state.client.clientid,
					groupby: " group by fromid order by ct desc "
				},
			};
		},
		created: function() {
			this.search();
		},
		methods: {
			search: function(param) {
				this.msgs = [];
				this.pageInfo.current = 1;
				this.loadMsg(param);
			},
			loadMore: function() {
				this.pageInfo.current++;
				this.loadMsg();
			},
			loadMsg: function() {
				this.api("/msg/page").send(this.pageInfo).then(data => {
					for (let index in data.msgs.records) {
						let record = data.msgs.records[index];
						this.msgs.push(record);
					}
					this.pageInfo.total = data.msgs.total;
				});
			},
			toChat: function(id) {
				uni.navigateTo({
					url: "/pages/cjl/chat?id="+id
				})
			}
		}
	}
</script>

<style>
</style>